<template>
  <div>
    <a-card :bordered="false">
      <f-search-form @searchHandler="searchHandler">
        <f-search-form-item label="专业包代码" name="majorCode" slot="advanced"/>
        <f-search-form-item label="专业包名称" name="majorName"/>
        <f-search-form-item label="工程包代码" name="packageNo" slot="advanced"/>
        <f-search-form-item label="工程包名称" name="packageName"/>
        <f-search-form-item label="供应商代码" name="materialArea" slot="advanced"/>
      </f-search-form>
      <f-table ref="table" rowKey="materialPackage100Id" :scroll="{x:showColumns.length*150}" :columns="showColumns"
               :exportBtn="false"
               :multiple="false" :operator="operator" :params="queryParam" :api="api.package"
               handler="materialPackagePageListHandler">
         <span slot="action" slot-scope="text, record, index">
          <template>
             <a @click="$refs.reportDetailsDrawer.showDrawer(record)">查看月报</a>
             <a-divider type="vertical"/>
          </template>
        </span>
      </f-table>
      <report-drawer ref="reportDrawer"></report-drawer>
      <report-details-drawer ref="reportDetailsDrawer" :listType="1"></report-details-drawer>
    </a-card>
  </div>
</template>
<script>
  import api from './js/apiPackage'
  import reportDetailsDrawer from './report_details_drawer'

  export default {
    name: 'TableList',
    props: {
      detailsParams: {}
    },
    components: {
      reportDetailsDrawer
    },
    data() {
      let me = this
      //操作按钮
      let operator = []
      return {
        api: Object.assign(api, this.api),
        //列表初始化查询参数
        queryParam: {},
        showColumns: [],
        showVal: 1,
        // 表头
        columns: [
          {
            title: '序号',
            width: 80,
            align: 'center',
            customRender: (text, record, index) => index + 1
          },
          {
            title: '分包Id',
            width: 180,
            align: 'center',
            dataIndex: 'materialPackage100Id'
          },
          {
            title: '项目代码',
            width: 150,
            align: 'center',
            dataIndex: 'projectCode'
          },
          {
            title: '项目名称',
            width: 150,
            align: 'center',
            dataIndex: 'projectName'
          },
          {
            title: '专业名称',
            width: 150,
            align: 'center',
            dataIndex: 'majorName'
          },
          {
            title: '专业代码',
            width: 150,
            align: 'center',
            dataIndex: 'majorCode'
          },
          {
            title: '工程包名称',
            width: 150,
            align: 'center',
            dataIndex: 'packageName'
          },
          {
            title: '工程包代码',
            width: 150,
            align: 'center',
            dataIndex: 'packageNo'
          },
          {
            title: '服务代码',
            width: 150,
            align: 'center',
            dataIndex: 'serviceCode'
          },
          {
            title: '服务WBS代码',
            width: 150,
            align: 'center',
            dataIndex: 'serviceWbsCode'
          },
          {
            title: '科目名称',
            width: 150,
            align: 'center',
            dataIndex: 'subjectName'
          },
          {
            title: '层级号',
            width: 150,
            align: 'center',
            dataIndex: 'levelNo'
          },
          {
            title: '分承包发包项目描述',
            width: 200,
            align: 'center',
            dataIndex: 'packageDesc'
          },
          {
            title: '对外合同描述',
            width: 150,
            align: 'center',
            dataIndex: 'contractDesc'
          },
          {
            title: '区域',
            width: 150,
            align: 'center',
            dataIndex: 'materialArea'
          },
          {
            title: '系统',
            width: 150,
            align: 'center',
            dataIndex: 'materialUse'
          },
          {
            title: '合同清单工程量',
            width: 150,
            align: 'center',
            dataIndex: 'contractBillQuantity'
          },
          {
            title: '标前工程量',
            width: 150,
            align: 'center',
            dataIndex: 'beforeMarkQuantity'
          },
          {
            title: '100预算成本工程量',
            width: 200,
            align: 'center',
            dataIndex: 'costQuantity100'
          },
          {
            title: '200预算成本工程量',
            width: 200,
            align: 'center',
            dataIndex: 'costQuantity200'
          }
        ],
        operator: operator
      }
    },
    created() {
      this.detailsParams.isReport = true
      this.queryParam = this.detailsParams
      this.getBusProjectSupplierList()
    },
    methods: {
      getBusProjectSupplierList() {
        this.showColumns = this.columns
        this.http.get(this, {
          url: this.api.package.getBusProjectSupplierList,
          data: this.detailsParams,
          success(me, data) {
            console.log(data)
            for (let i in data) {
              let info = data[i]
              me.columns.push({
                title:info.supplierName + '合同量',
                width: 250,
                align: 'center',
                dataIndex: 'supplierNum' + info.index
              })
            }
            me.columns.push({
              title: '操作',
              width:150,
              align: 'center',
              scopedSlots: { customRender: 'action' },
              fixed: 'right'
            })
          }
        })
      }
    }
  }
</script>
